
#include "LadderDuplicate.h"
#include "Common/EventDefine.h"
#include "Duplicate/DuplicateMgr.h"
#include "Character/Part.h"
#include "Character/monster/MonsterMgr.h"
#include "Character/monster/MonsterRefCfg.h"
#include "Character/HuoYueDuPart.h"

LadderDuplicate::LadderDuplicate()
{
	m_byType = (int8_t)EDuplicateType::EDuplicateType_Ladder;
}

LadderDuplicate::~LadderDuplicate()
{

}

bool LadderDuplicate::Init(uint32_t nDuplicateID, uint32_t nSceneID, IBrushMonster *pBrush)
{
	return  Duplicate::Init(nDuplicateID, nSceneID, pBrush);
}

//
void LadderDuplicate::UnInit()
{
	Duplicate::UnInit();
}

void LadderDuplicate::OnTimerUpdate(uint32_t nTimerID)
{
	switch (nTimerID)
	{
	case ETimer_Flop:
	{
		//翻牌结束
		OnCommon_FlopStateEnd();
	}
	break;
	case ETimer_Clean:
	{
		OnCommon_CleanStateEnd();
	}
	break;
	case ETimer_Destory:
	{
		LogDebugFmtPrint("[logic] LadderDuplicate destory .... duplicateid:%u , sceneid:%u, mapid:%u ", m_nDuplicateID, m_nSceneID, m_nMapID);
		//回收
		OnCommon_DestoryStateEnd();
	}
	break;
	}
}

void LadderDuplicate::OnExecuteEvent(uint16_t nEventID, uint32_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen)
{
	_UNUSE(nEventID);
	_UNUSE(nSrcID);
	_UNUSE(bySrcType);
	_UNUSE(nLen);
}
//生物进入场景
void LadderDuplicate::OnCreatureEnter(Creature *pCreature)
{
	if (CREATURE_PLAYER == pCreature->CreatureKind())
	{
		//进入副本，塔防活跃度
		HuoYueDuPart*pHuoyuePart = dynamic_cast<HuoYueDuPart*>(pCreature->GetPart(PART_HUOYUEDU));
		if (nullptr != pHuoyuePart)
		{
			pHuoyuePart->AddHuoYueDuRecord(HYDT_LADDER_DUP);
		}
	}
}

//生物离开副本
void LadderDuplicate::OnPlayerLeave(Player *pPlayer)
{
}

//是否能进入
bool LadderDuplicate::OnCanEnter(Creature *pCreature)
{
	//新手副本准备状态才能进入
	if (GetDuplicateState() == (int8_t)EDuplicateState::EDuplicateState_Ready)
	{
		if (m_setPlayer.size() < 1) //天梯副本只允许一个人
		{
			return true;
		}
	}

	return false;
}

//进入区域
bool LadderDuplicate::OnEnterArea(uint32_t nAreaID)
{
	nAreaID = nAreaID;
	return true;
}

//复活
void LadderDuplicate::OnRelive(Player *pPlayer, int8_t byType)
{
	pPlayer = pPlayer;
	byType = byType;
}

void LadderDuplicate::OnReady_State()
{

}

void LadderDuplicate::OnBegin_State()
{
	OnCommon_DupBeginState();
}

void LadderDuplicate::OnFinish_State()
{
	OnCommon_DupFinishState();
}

void LadderDuplicate::OnFlop_State()
{
	//设置抽奖时间 20s
	LogDebugFmtPrint("[logic] LadderDuplicate::OnDuplicateState_Flop....duplicateid:%u , sceneid:%u ", m_nDuplicateID, m_nSceneID);
	OnCommon_DupFlopState();
}

void LadderDuplicate::OnClean_State()
{
	//删除抽奖定时器
	OnCommon_DupCleanState();
}

void LadderDuplicate::OnDestory_State()
{
	OnCommon_DupDestoryState();
}
